<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/8/14
  Time: 15:29
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>生成二维码</title>

    <script type="application/javascript" src="<%=request.getContextPath() %>/js/jquery.min.js"></script>
    <script type="application/javascript" src="<%=request.getContextPath() %>/js/jquery.qrcode.min.js"></script>

</head>
<body>
<h2>生成的二维码如下：</h2>
<div id="qrcode"></div>

<script type="text/javascript">
    /*解决中文*/
    function utf16to8(str) {
        var out, i, len, c;
        out = "";
        len = str.length;
        for (i = 0; i < len; i++) {
            c = str.charCodeAt(i);
            if ((c >= 0x0001) && (c <= 0x007F)) {
                out += str.charAt(i);
            } else if (c > 0x07FF) {
                out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
                out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
                out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
            } else {
                out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
                out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
            }
        }
        return out;
    }
    $(function () {
        jQuery('#qrcode').qrcode(utf16to8("我是中国人!"));
    })
</script>

</body>
</html>
